﻿package mortal.game.view.chat.selectPanel
{
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.mvc.core.*;

    public class ShieldTypePanel extends CallSprite
    {
        private var _dataArray:Array;
        private var _dicBtnShieldObj:Dictionary;

        public function ShieldTypePanel(param1:Array)
        {
            this._dicBtnShieldObj = new Dictionary();
            this._dataArray = param1;
            var _loc_2:int = 0;
            while (_loc_2 < this._dataArray.length)
            {
                
                (this._dataArray[_loc_2] as Object).isShield = false;
                _loc_2++;
            }
            this.createChildren();
            return;
        }// end function

        private function createChildren() : void
        {
            var _loc_1:* = ResourceConst.getScaleBitmap("ToolTipBg");
            _loc_1.width = 72;
            _loc_1.height = this._dataArray.length * 25 + 10;
            this.addChild(_loc_1);
            var _loc_2:int = 0;
            while (_loc_2 < this._dataArray.length)
            {
                
                this.createButton(_loc_2, this._dataArray[_loc_2]);
                _loc_2++;
            }
            return;
        }// end function

        private function createButton(param1:int, param2:Object) : void
        {
            var _loc_3:GButton = null;
            var _loc_4:Bitmap = null;
            _loc_3 = new GButton();
            _loc_3.x = 6;
            _loc_3.y = param1 * 25 + 5;
            _loc_3.width = 60;
            _loc_3.height = 24;
            _loc_3.styleName = "ChatTabBtn";
            _loc_3.name = param2["name"];
            _loc_3.label = param2["label"];
            _loc_3.textField.filters = [FilterConst.glowFilter];
            _loc_3.addEventListener(MouseEvent.CLICK, this.btnClickHandler);
            this.addChild(_loc_3);
            _loc_4 = GlobalClass.getBitmap("Gag");
            _loc_4.x = 6;
            _loc_4.y = 5;
            _loc_4.width = 14;
            _loc_4.height = 14;
            _loc_4.visible = false;
            _loc_3.addChild(_loc_4);
            this._dicBtnShieldObj[_loc_3] = _loc_4;
            return;
        }// end function

        private function btnClickHandler(event:MouseEvent) : void
        {
            var _loc_2:* = this.getObjByName((event.target as GButton).name);
            if (_loc_2)
            {
                if (_loc_2["isShield"])
                {
                    _loc_2["isShield"] = false;
                    (this._dicBtnShieldObj[event.target] as DisplayObject).visible = false;
                    (event.target as GButton).label = _loc_2["label"];
                }
                else
                {
                    _loc_2["isShield"] = true;
                    (this._dicBtnShieldObj[event.target] as DisplayObject).visible = true;
                    (event.target as GButton).label = "    " + _loc_2["label"];
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChatShield, {label:_loc_2["label"], isShield:_loc_2["isShield"]}));
            }
            return;
        }// end function

        public function getNotShieldNameList() : Array
        {
            var _loc_2:Object = null;
            var _loc_1:* = new Array();
            for each (_loc_2 in this._dataArray)
            {
                
                if (!_loc_2["isShield"])
                {
                    _loc_1.push(_loc_2["name"]);
                }
            }
            return _loc_1;
        }// end function

        private function getObjByName(param1:String) : Object
        {
            var _loc_2:Object = null;
            for each (_loc_2 in this._dataArray)
            {
                
                if (_loc_2.hasOwnProperty("name") && _loc_2["name"] == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

    }
}
